package com.wuzy.aidlserver.slice;

import com.wuzy.aidlserver.RemoteService;
import com.wuzy.aidlserver.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class TransferAbilitySlice extends AbilitySlice {
    private static final HiLogLabel TAG = new HiLogLabel(3, 0xD001100, "RemoteService");
    public static final String ACTION_FROM_SELF = "com.wuzy.aidlserver.TransferAbility.FROM_SELF";
    public static final String ACTION_FROM_OTHER = "com.wuzy.aidlserver.TransferAbility.FROM_OTHER";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        HiLog.error(TAG, "TransferAbilitySlice::onStart");
        super.setUIContent(ResourceTable.Layout_ability_transfer);

        if (intent!= null) {
            if (ACTION_FROM_OTHER.equals(intent.getAction())) {
                Intent newIntent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.wuzy.aidlserver")
                        .withAbilityName(RemoteService.class)
                        .build();
                newIntent.setOperation(operation);
                startAbility(newIntent);
            } else if (ACTION_FROM_SELF.equals(intent.getAction())) {
                Intent newIntent = new Intent();
                newIntent.setAction("com.wuzy.aidlclient.TransferAbility.FROM_OTHER");
                newIntent.setFlags(Intent.FLAG_ABILITY_NEW_MISSION);
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.wuzy.aidlclient")
                        .withAbilityName("com.wuzy.aidlclient.TransferAbility")
                        .build();
                newIntent.setOperation(operation);
                startAbility(newIntent);
                setTransitionAnimation(0,0);
            }
        }
        terminateAbility();
    }

    @Override
    public void onActive() {
        super.onActive();
        HiLog.error(TAG, "TransferAbilitySlice::onActive");
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
